﻿/*
ParallelPlatform Project - A web platform to distribute and share knowledge
Online Editor - An online tool to create and play animations
Copyright (C) 2011 Daniel Guerrero Martínez & Sergio Rodríguez Lumley

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package Classes{
//	import flash.display.MovieClip;
//	import flash.utils.getDefinitionByName;
//	import flash.utils.getQualifiedClassName;
//	import flash.events.MouseEvent;

	import flash.text.TextField;
	import flash.text.Font;
	
	public class ShapeObjectDatabase extends BasicShapeObjectDatabase {
		
		// Specifies the basic form of the figure
		static public const SQUARE:uint = 0;
		static public const ROUNDRECT:uint = 1;
		static public const CIRCLE:uint = 2;
		static public const ARROW:uint = 3;
		static public const ELLIPSE:uint = 4;
		
		static private const SHADOWCOLORPALETE:Array =
			[0x00FF00, 0x0000FF, 0xFF0000, 0x00FFFF, 0xFF00FF, 0xFFFF00, 0xFFFFFF,
			 0xCCFFCC, 0xCCCCFF, 0xFFCCCC, 0xCCFFFF, 0xFFCCFF, 0xFFFFCC, 0xDDDDDD,
			 0x44FF44, 0x4444FF, 0xFF4444, 0x44FFFF, 0xFF44FF, 0xFFFF44, 0x666666,
			 0xAAFFAA, 0xAAAAFF, 0xFFAAAA, 0xAAFFFF, 0xFFAAFF, 0xFFFFAA, 0x000000,
			 0x22FF22, 0x2222FF, 0xFF2222, 0x22FFFF, 0xFF22FF, 0xFFFF22, 0x444444,
			 0x88FF88, 0x8888FF, 0xFF8888, 0x88FFFF, 0xFF88FF, 0xFFFF88, 0xAAAAAA,
			 0x66FF66, 0x6666FF, 0xFF6666, 0x66FFFF, 0xFF66FF, 0xFFFF66, 0x888888,
			 0xAACCAA, 0xAAAACC, 0xCCAAAA, 0xAACCCC, 0xCCAACC, 0xCCCCAA, 0xCCCCCC
			 ]
		
		static private const sArrow:uint = 0;
		static private const sCellL:uint = 1;
		static private const sCellM:uint = 2;
		static private const sCellS:uint = 3;
		static private const sCircleL:uint = 4;
		static private const sCircleM:uint = 5;
		static private const sCircleS:uint = 6;
		static private const sGroupL:uint = 7;
		static private const sGroupM:uint = 8;
		static private const sGroupS:uint = 9;
		static private const sProcessL:uint = 10;
		static private const sProcessM:uint = 11;
		static private const sProcessS:uint = 12;
		static private const sText:uint = 13;
		static private const sConsoleL:uint = 14;
		static private const sConsoleM:uint = 15;
		static private const sConsoleS:uint = 16;
		static private const sThreadL:uint = 17;
		static private const sThreadM:uint = 18;
		static private const sThreadS:uint = 19;
		static private const sThreadBall:uint = 20;
		static private const sThreadRoll:uint = 21;
		static private const sCustom:uint = 22;
		
		/**
		  ClassList is accessed though static constants in order to increase
		  readability. It contains all shape's of editor.
		*/
		static private const classes:Array = [ShapeArrow,
							   ShapeCellL, ShapeCellM, ShapeCellS,
							   ShapeCircleL, ShapeCircleM, ShapeCircleS,
							   ShapeGroupL, ShapeGroupM, ShapeGroupS,
							   ShapeProcessL, ShapeProcessM, ShapeProcessS,
							   ShapeText,
							   ShapeConsoleL, ShapeConsoleM, ShapeConsoleS,
							   ShapeThreadL, ShapeThreadM, ShapeThreadS,
							   ShapeThreadBall,
							   ShapeThreadRoll,
							   ShapeCustom
							   ];
			
		// ----- OVERRIDES ----- //
		
		/**
		  Query to check if the shape is editable, as editable we
		  understand that it is possible to paint on it
		  @param shape ShapeObject to test if it is editable
		*/
		static public function isEditable(shape:BasicShapeObject):Boolean{
			return BasicShapeObjectDatabase.isEditable(shape, classes);
		}
		
		/**
		  Query if shape from editor is able to have text
		  @param shape ShapeObject to test if it has text
		  @return Boolean with true if it can have, false otherwise
		*/
		static public function hasText(shape:BasicShapeObject):Boolean{
			return BasicShapeObjectDatabase.hasText(shape, classes);
		}
		
		/**
		  Returns a new TextField associated to a ShapeObject. This
		  TextField has the font and format specific to the ShapeObject
		  type. Note this function does NOT check if the ShapeObject can
		  have a TextField or not, this should by checked before calling
		  this function.
		  @param shape ShapeObject of which we want to get the new TextField
		  @return TextField of the specified ShapeObject
		*/
		static public function getTextField(shape:BasicShapeObject):TextField{
			return BasicShapeObjectDatabase.getTextField(shape, classes);
		}
		
		/**
		  Returns the characters that ShapeObjects are able to show
		*/
		static public function getRestrictedCharacters():String{
			return BasicShapeObjectDatabase.getRestrictedCharacters();
		}
		
		// -------- PUBLIC FUNCTIONS -------- //
		
		/**
		  Gets the list of all available shapes in the editor, it gives it
		  in the form of a table, grouped by context.
		  @return Array.<Array.<String> > with all the qualified names of the Shapes
		*/
		static public function getAvailableShapes():Array{
			// By now 6 groups (Cell, Process, Thread, Group, Circle, Console)
			var ret:Array = new Array(6);
			
			//ret[i] = new Vector.<String>(3); // For each group, there is S, M and L sizes
			ret[0] = ["ShapeCellL", "ShapeCellM", "ShapeCellS"];
			ret[1] = ["ShapeProcessL", "ShapeProcessM", "ShapeProcessS"];
			ret[2] = ["ShapeThreadL", "ShapeThreadM", "ShapeThreadS"];
			ret[3] = ["ShapeGroupL", "ShapeGroupM", "ShapeGroupS"];
			ret[4] = ["ShapeCircleL", "ShapeCircleM", "ShapeCircleS"];
			ret[5] = ["ShapeConsoleL", "ShapeConsoleM", "ShapeConsoleS"];
			
			return ret;
		}
		
		/**
		  Gets the basic form of the specified shapeObject
		  @param shape ShapeObject to find out the form
		  @return uint with the basic form defined by this class constants
		*/
		static public function getBasicForm(shape:BasicShapeObject):uint{
			var ret:uint = SQUARE;

			if(shape is ShapeProcessL ||
			   shape is ShapeProcessM ||
			   shape is ShapeProcessS ){
				ret = CIRCLE;
			}else if(shape is ShapeGroupL ||
			   shape is ShapeGroupM ||
			   shape is ShapeGroupS ){
				ret = ROUNDRECT;
			}else if(shape is ShapeCellL ||
			   shape is ShapeCellM ||
			   shape is ShapeCellS ){
				ret = ROUNDRECT;
			}else if(shape is ShapeArrow){
				ret = ARROW;
			}
			
			return ret;
		}
		
		/**
		  Gets a basic color through an index, the same color will always
		  be given with the same index. The color that will be returned can
		  be considered as pseudo-random, as we don't care what color will
		  be, as long as it is always the same one for the same index.
		  @param i uint with the index of a color that we want.
		*/
		static public function getBasicColor(i:uint):uint{
			if(i >= SHADOWCOLORPALETE.length)
				return (0x333333 + i*0x000033)%0xFFFFFF;
			else
				return SHADOWCOLORPALETE[i];
		}
		
	}
}